package com.hex.ds.hdtp.core.inf.license.activation.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.license.activation.mapper.IFuncActivationMapper;
import com.hex.ds.hdtp.core.inf.license.activation.po.FuncActivationPo;
import com.hex.ds.hdtp.core.inf.license.activation.repository.IFuncActivationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FuncActivationRepository implements IFuncActivationRepository {

    private final IFuncActivationMapper funcActivationMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    @Override
    public Page<FuncActivationPo> queryListByPage(FuncActivationPo funcActivationPo, Page page) {
        final IPage tmpPageResult = funcActivationMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , funcActivationPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    @Override
    public Integer selectAllCount() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return funcActivationMapper.selectCount(queryWrapper);
    }

    @Override
    public FuncActivationPo selectOne() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return funcActivationMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer update(FuncActivationPo funcActivationPo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("pk_id", funcActivationPo.getPkId());
        return funcActivationMapper.update(funcActivationPo, queryWrapper);
    }

    @Override
    public Integer deleteAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return funcActivationMapper.delete(queryWrapper);
    }

    @Override
    public FuncActivationPo queryById(String pkId) {
        return funcActivationMapper.selectById(pkId);
    }

    @Override
    public Integer add(FuncActivationPo funcActivationPo) {
        return funcActivationMapper.insert(funcActivationPo);
    }

    @Override
    public Integer modifyById(FuncActivationPo funcActivationPo) {
        return funcActivationMapper.updateById(funcActivationPo);
    }

    @Override
    public Integer removeById(String pkId) {
        return funcActivationMapper.deleteById(pkId);
    }

}

